package br.com.midiaseducativas.tutor.jogos.quiz {
	import br.com.midiaseducativas.tutor.jogos.quiz.event.CheckGroupEvent;
	import br.com.midiaseducativas.tutor.jogos.quiz.vo.AnswerVO;
	
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	
	import flashx.textLayout.elements.TextFlow;
	
	
	public class Answer extends EventDispatcher{
		
		private var _visual:AnswerSWC;
		private var _vo:AnswerVO;
		
		private var _selected:Boolean;
		
		public function Answer(pVO:AnswerVO) {
			
			this.visual = new AnswerSWC();
			this.vo = pVO;
			this.visual.text.htmlText = this.vo.text;
			this.selected = false;
			
			this.visual.mark.addEventListener(MouseEvent.CLICK, onClick);
			this.visual.mark.buttonMode = true;
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}

		public function set selected(value:Boolean):void
		{
			_selected = value;
			if (!_selected) {
				this.visual.mark.gotoAndStop(1);
			}else {
				this.visual.mark.gotoAndStop(2);
			}
		}

		public function get vo():AnswerVO
		{
			return _vo;
		}

		public function set vo(value:AnswerVO):void
		{
			_vo = value;
		}

		public function get visual():AnswerSWC
		{
			return _visual;
		}

		public function set visual(value:AnswerSWC):void
		{
			_visual = value;
		}

		protected function onClick(event:MouseEvent):void {
			/*if (this.selected) {
				this.visual.mark.gotoAndStop(1);
			}else {
				this.visual.mark.gotoAndStop(2);
			}*/ 
			
			this.selected = !this.selected;
			var eventGroup:CheckGroupEvent = new CheckGroupEvent(CheckGroupEvent.SELECTED);
			eventGroup.answer = this;
			this.dispatchEvent(eventGroup);
		}
		
	}
}